from loaddata import mgDB
from analysis import util
# 总进球数据模型管理

db = mgDB.JinCaiDatabase()


# 获取历史数据(开始年到现在)
def getHistoryDataFromYear(year):
    ds = db.getHistoryDataFromYear(year)
    historys = []
    for d in ds:
        rd = util.formatHAFUData(d, False)
        if rd:
            historys.append(rd)
    return historys

# 获取要分析的数据
def getSellingData(matchId):
        selling = db.getSellingData(matchId)
        return util.formatHAFUData(selling, True)

# 获取近一年的历史数据(总进球)
def getHistoryDataByNearYear():
        ds = db.getHistoryDataByNearYear()
        historys = []
        for d in ds:
            rd = util.formatHAFUData(d, False)
            if rd:
                historys.append(rd)
        return historys

# 获取近一月的历史数据(总进球)
def getHistoryDataByNearMonth(month):
        ds = db.getHistoryDataByNearMonth(month)
        historys = []
        for d in ds:
            rd = util.formatHAFUData(d, False)
            if rd:
                historys.append(rd)
        return historys

# 根据matchId查询历史比赛场次
def getHistoryDataByMatchID(matchId):
        m = db.getHistoryDataByMatchID(matchId)
        rd = util.formatHAFUData(m, False)
        if rd:
            return rd
        else:
            return None


# 获取历史数据(指定某一年的数据)
def getHistoryDataByYear(year):
        ds = db.getHistoryDataByYear(year)
        historys = []
        for d in ds:
            rd = util.formatHAFUData(d, False)
            if rd:
                historys.append(rd)
        return historys


# 获取历史数据(开始时间，结束时间)
def getHistoryDataBystart(datestart,dateend):
        ds = db.getHistoryDataBystart(datestart,dateend)
        historys = []
        for d in ds:
            rd = util.formatHAFUData(d, False)
            if rd:
                historys.append(rd)
        return historys

# 获取正在售卖的总进球数据
def getSellingData(matchId):
    d = db.getSellingData(matchId)
    return util.formatHAFUData(d, True)
